package work.xkong.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import work.xkong.common.ResponseRest;
import work.xkong.entity.Student;
import work.xkong.service.IStudentService;
import work.xkong.utils.TokenUtils;
import work.xkong.vo.inputvo.StudentInfoInputVo;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author NuanYang
 * @since 2022-11-21
 */
@RestController
@RequestMapping("/student")
@Slf4j
public class StudentController {
    @Autowired
    private IStudentService studentService;

    @GetMapping("/getStudentInfo")
    public ResponseRest getStudentInfo(HttpServletRequest request) {
        String jwt = request.getHeader("Authorization");
        String studentId = (String) TokenUtils.getParseToken(jwt).get(Claims.ID);

        return studentService.getStudentInfo(Integer.parseInt(studentId));
    }

    @PutMapping("/updateStudentInfo")
    public ResponseRest updateStudentInfo(@RequestBody Student student, HttpServletRequest request) {
        log.info("前端接受的学生信息：" + student);
        String jwt = request.getHeader("Authorization");
        String studentId = (String) TokenUtils.getParseToken(jwt).get(Claims.ID);

        student.setStudentId(Integer.parseInt(studentId));

        return studentService.updateBy(student);
    }

}
